package com.android.jixin.channel.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.jixin.channel.MainActivity;
import com.android.jixin.channel.R;
import com.android.jixin.channel.base.BaseActivity;
import com.android.jixin.channel.presenter.impl.LoginPresenterImpl;
import com.android.jixin.channel.view.ILoginView;
import com.android.library.util.StringUtils;
import com.rengwuxian.materialedittext.MaterialEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;

public class LoginActivity extends BaseActivity<LoginPresenterImpl> implements ILoginView {

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.phone)
    MaterialEditText phone;
    @BindView(R.id.code)
    MaterialEditText code;
    @BindView(R.id.login)
    TextView login;

    @Override
    protected void initView() {
        getSupportActionBar().setHomeButtonEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);

        login.setEnabled(false);
        title.setText(getString(R.string.home_title));
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_login;
    }

    @Override
    protected void initInjector() {
        getActivityComponent().inject(this);
    }

    @OnTextChanged({R.id.phone, R.id.code})
    void onhoneChanged(){
        mPresenter.setEnable(phone.getText().toString(), code.getText().toString());
    }

    @OnClick({R.id.getcode, R.id.login, R.id.protocol, R.id.apply})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.getcode:

                break;
            case R.id.login:
                readyGo(MainActivity.class);
                break;
            case R.id.protocol:
                break;
            case R.id.apply:
                readyGo(RegisterActivity.class);
                break;
        }
    }

    private void getCode(){
        mPresenter.getCode(phone.getText().toString());
    }

    @Override
    public void setLoginEnable(boolean enable) {
        login.setEnabled(enable);
    }
}
